/* eslint-disable perfectionist/sort-imports */

// core
import { createApp } from "vue"
import { pinia } from "@/pinia"
import { router } from "@/router"
import { installPlugins } from "@/plugins"
import App from "@/App.vue"
// css
import "normalize.css"
import "nprogress/nprogress.css"
import "element-plus/theme-chalk/index.css"
import "element-plus/theme-chalk/dark/css-vars.css"
import "vxe-pc-ui/lib/style.css"
import "vxe-table/lib/style.css"
import "@vxe-ui/plugin-render-element/dist/style.css"
import "@@/assets/styles/index.scss"
import "virtual:uno.css"
import { getViewText } from "./common/utils/validate"
// vue-flow
import "@vue-flow/core/dist/style.css"
import "@vue-flow/core/dist/theme-default.css"
// icon
import "@@/assets/iconfont/iconfont1/iconfont.css"
import "@@/assets/iconfont/iconfont2/iconfont.css"
import "@@/assets/fontawesome-free-5.11.2-web/css/all.min.css"
// jsmind
import "jsmind/style/jsmind.css"

import 'virtual:svg-icons-register'

import ElTableInfiniteScroll from "el-table-infinite-scroll"
import ElementPlus from "element-plus"

import { preloadCriticalModules, preloadNonCriticalModules } from "@@/utils/preload"

if (import.meta.env.DEV) {
  window.CESIUM_BASE_URL = "/node_modules/cesium/Build/Cesium/"
}
if (import.meta.env.PROD) {
  window.CESIUM_BASE_URL = "/cesium/"
  window.MonacoEnvironment = {
    baseUrl: "/monaco-editor/",
    getWorkerUrl(moduleId, label) {
      return `./monaco-editor/vs/${label}.worker.js`
    }
  }
}

// 创建应用实例
const app = createApp(App)

app.config.globalProperties.$getViewText = getViewText

// 安装插件（全局组件、自定义指令等）
installPlugins(app)

app.use(ElTableInfiniteScroll)
app.use(ElementPlus)

// 安装 pinia 和 router
app.use(pinia).use(router)

// router 准备就绪后挂载应用
router.isReady().then(() => {
  app.mount("#ma-app")
})

// 预加载关键模块
preloadCriticalModules()
// 延迟预加载非关键模块
preloadNonCriticalModules()
